import moment from 'moment'

//设置 el-date-picker 默认的起始与结束时刻; 第一项控制开始日期的时间值，第二项控制结束日期的时间值
export const defaultTimeValue: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] // '00:00:00', '23:59:59'

export const defaultShortcuts = [
  {
    text: '今天',
    value: () => [moment().startOf('day'), moment().endOf('day')]
  },
  {
    text: '昨天',
    value: () => [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')]
  },
  {
    text: '近三天',
    value: () => [moment().subtract(3, 'days').startOf('day'), moment().endOf('day')]
  },
  {
    text: '近七天',
    value: () => [moment().subtract(7, 'days').startOf('day'), moment().endOf('day')]
  },
  {
    text: '本周',
    value: () => [moment().weekday(1).startOf('day'), moment().endOf('day')]
  },
  {
    text: '上周',
    value: () => [
      moment()
        .week(moment().week() - 1)
        .weekday(1)
        .startOf('day'),
      moment()
        .week(moment().week() - 1)
        .weekday(7)
        .endOf('day')
    ]
  },
  {
    text: '本月',
    value: () => [moment().startOf('month').startOf('day'), moment().endOf('day')]
  },
  {
    text: '上月',
    value: () => [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  }
]

/**
 *  分钟转xx天xx时xx分
 *  @param1 mins: 分钟
 */
export function minsToDate(mins: number | string) {
  mins = Number(mins)
  const hourMinsCount = 60
  const d = Math.floor(mins / (hourMinsCount * 24))
  const res = mins % (hourMinsCount * 24)
  const h = Math.floor(res / hourMinsCount)
  const m = res % hourMinsCount
  let result = ''
  if (d > 0) result += d + '天'
  if (h > 0) result += h + '时'
  if (m > 0) result += +m.toFixed(2) + '分'
  return result
}

/**
 * 秒转时长
 * @param secs 时长（秒）
 * @returns X天X时X分X秒
 */
export function secondToDate(secs?: number) {
  secs = secs || 0
  let result = ''
  const d = Math.floor(secs / 86400)
  const h = Math.floor((secs / 3600) % 24)
  const m = Math.floor((secs / 60) % 60)
  const s = Math.floor(secs % 60)
  if (d > 0) result += d + '天'

  if (h > 0) result += h + '时'

  if (m > 0) result += m + '分'

  if (s > 0) result += s + '秒'

  return result
}
